package com.alibaba.travel.member.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * swagger-knife4j 配置
 *
 * @author yyf
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig implements WebMvcConfigurer {
    /**
     *用于定制化配置Docket的bean实例
     */
    @Bean
    public Docket demoApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("(?!/error.*).*"))
                .build()
                .useDefaultResponseMessages(false)
                .apiInfo(ApiInfo());
    }


    /**
     * 定制化信息的主要设置处
     */
    private ApiInfo ApiInfo() {
        Contact contact = new Contact("", "作者的个人社交主页", "作者的邮箱");

        return new ApiInfo(
                "用户模块",
                "简介：接口文档",
                "版本号:1.0",
                "网页：这是一个网页链接",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>()
        );
    }


}
